#pragma once
#include <iostream>
#include <ctime>

class Task
{
public:
    Task(int Leftoperand = 0, char Operator = '\0', int Rightoperand = 0)
        : Leftoperand_(Leftoperand), Operator_(Operator), Rightoperand_(Rightoperand)
    {
    }

public:
    int run()
    {
        int result = 0;
        switch (Operator_)
        {
        case '+':
            result = Leftoperand_ + Rightoperand_;
            break;
        case '-':
            result = Leftoperand_ - Rightoperand_;
            break;
        case '*':
            result = Leftoperand_ * Rightoperand_;
            break;
        case '/':
            if (Rightoperand_ == 0)
            {
                std::cout << "Divide by zero error! ! !" << std::endl;
                result = -1;
            }
            else
            {
                result = Leftoperand_ / Rightoperand_;
            }
            break;
        case '%':
            if (Rightoperand_ == 0)
            {
                std::cout << "Modulo by zero error! ! !" << std::endl;
                result = -1;
            }
            else
            {
                result = Leftoperand_ % Rightoperand_;
            }
            break;
        default:
            std::cout << "Illegal operator: " << Operator_ << std::endl;
            break;
        }
        return result;
    }

public:
    void operator()(unsigned long int pid)
    {
        int result = run();
        std::cout << Leftoperand_ << " " << Operator_ << " " << Rightoperand_ << " = "
                  << result << " | pid: " << pid << " | " << (long int)time(nullptr) << std::endl;
    }

    void GetMemberVal(int &x, char &op, int &y)
    {
        x = Leftoperand_;
        op = Operator_;
        y = Rightoperand_;
    }

private:
    int Leftoperand_;  // 左操作数
    char Operator_;    // 加减乘除字符
    int Rightoperand_; // 右操作数
};